<p>
Falling Fruit is built on public data, and on the generosity of urban foragers willing to share their finds with others. We want urban food sources to reach as many people as possible, and we believe that everyone should have equal access to the collective fruit of our labors. In the spirit of open data, behold! The entire database:
</p>

<blockquote>
<a href="/data.csv.bz2">data.csv.bz2</a> (<%= File.size(Rails.root.join("public","data.csv.bz2"))/(1024**2) %> MB)<br>
<i>last updated <%= File.mtime(Rails.root.join("public","data.csv.bz2")).strftime "%Y-%m-%d %H:%M:%S %Z" %></i>
</blockquote>

<p>
But beware. Once uncompressed, the data becomes a huge file that causes most spreadsheet software to implode. Only those interested in manipulating the data in it's entirety need to go this route. For most, a better alternative is to selectively retrieve points of interest using the download tool integrated into the <a href="/">map</a>.
</p>

<p>
It should go without saying that we take no responsibility for the accuracy of the data - it is provided as is, <i>caveat emptor</i>. If you do something cool with the data, please <a href="mailto:feedback@fallingfruit.org">let us know</a>!
</p>

<h2>Summary of Sources</h2>

<% cache 'pages_data_type_summary_table' do
  @types = ActiveRecord::Base.connection.execute("SELECT t.id, t.scientific_name, t.scientific_synonyms, t.usda_symbol, t.wikipedia_url,
    t.name, t.synonyms, count(*) FROM types t, locations_types lt WHERE lt.type_id=t.id 
    GROUP BY t.id, t.scientific_name, t.usda_symbol, t.name ORDER BY t.name")
%>

The database currently contains <%= Type.count.to_s.gsub(/(?<=\d)(?=(?:\d{3})+\z)/, ',') %> edible source types (most, but not all, are plant species) distributed over <%= LocationsType.count.to_s.gsub(/(?<=\d)(?=(?:\d{3})+\z)/, ',') %> distinct locations. For each type, the following table lists common name(s), scientific name(s), prevalence, and links to Wikipedia and the US Department of Agriculture.
<br><br>

<table id="type_summary">
<thead>
<tr>
 <th>Common name</th>
 <th>Scientific name</th>
 <th>Links</th>
 <th>Count</th>
</tr>
</thead>
<tbody>
<% @types.each{ |t| %>
<tr>
<td>
<%= t["name"] unless t["name"].nil? %>
<%= "(#{t["synonyms"]})" unless t["synonyms"].nil? or t["synonyms"].strip == "" %>
</td>
<td>
<i><%= t["scientific_name"] unless t["scientific_name"].nil? %>
<%= "(#{t["scientific_synonyms"]})" unless t["scientific_synonyms"].nil? or t["scientific_synonyms"].strip == "" %>
</i>
</td>
<td>
<% unless t["wikipedia_url"].nil? %>
 <a href="<%= t["wikipedia_url"] %>"><img class="link_icon" src="/wikipedia_icon.png"></a>
<% end %>
<% unless t["usda_symbol"].nil? %>
 <a href="http://plants.usda.gov/java/profile?symbol=<%= t["usda_symbol"] %>"><img class="link_icon" src="/usda_icon.png"></a>
<% end %>
</td>
<td style="test-align: right;"><%= t["count"] %></td>
</tr>
<% } %>
</tbody>
</table>
<% end %>

<script type="text/javascript" charset="utf-8">
jQuery(document).ready(function(){
    jQuery('#type_summary').dataTable({
      "aaSorting": [[3,"desc"]]
    });
});
</script>
